/*
 * Copyright (c) 2009, Hamish Morgan. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the University of Sussex nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package locusts.common.net;

import java.awt.Rectangle;
import java.io.Serializable;
import javax.vecmath.Point2f;
import javax.vecmath.Tuple2f;
import locusts.common.Player;

/**
 *
 * @author Hamish Morgan
 */
public class InputMessage implements Serializable {

    public enum Type {

        PRESS, RELEASE, CLICK, ENTERED, EXITED, DRAG, MOVED, WHEEL_MOVED
    }
    private final Player player;
    private final Type type;
    private final int x;
    private final int y;

    private InputMessage(int x, int y, Player player, Type type) {
        if (player == null || type == null)
            throw new NullPointerException();
        this.x = x;
        this.y = y;
        this.player = player;
        this.type = type;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public Tuple2f getPosition() {
        return new Point2f(getX(), getY());
    }

    public Type getType() {
        return type;
    }

    public Player getPlayer() {
        return player;
    }

    @Override
    public String toString() {
        return "HitMessage (" + getX() + "," + getY() + ") Type: " + type + " Player: " + player;
    }

    public static class Mouse extends InputMessage {

        public Mouse(int x, int y, Player player, Type type) {
            super(x, y, player, type);
        }
    }

    public static class Touch extends InputMessage {

        private final int w;
        private final int h;

        public Touch(int x, int y, int w, int h, Player player, Type type) {
            super(x, y, player, type);
            this.w = w;
            this.h = h;
        }

        public int getWidth() {
            return w;
        }

        public int getHeight() {
            return h;
        }

        public Rectangle getRect() {
            return new Rectangle(-w / 2, -h / 2, w, h);
        }
    }
}
